package com.csx.springcloud.invoke.openfeign.consumer.base.controller;

import com.csx.springcloud.invoke.openfeign.consumer.base.client.ProviderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p> what does this class do ? </p>
 * <p> How does it work ?</p>
 * <p> Why does it do this ?</p>
 *
 * @author cuisongxu
 * @date 2023/8/5 周六 14:50
 */

@RequestMapping("/consumer")
@RestController
public class OpenFeignConsumerController {

    @Autowired
    private ProviderClient providerClient;


    @GetMapping("/hello")
    public String hello() {
        String username = providerClient.getUsername();
        return "hello " + username;
    }

    /**
     * 通过 spring.cloud.openfeign.client.config.default.readTimeout=5000 控制。单位 ms。
     * 一旦超时改时间 服务提供方还没有返回，则直接报 java.net.SocketTimeoutException: Read timed out 读超时异常
     */
    @GetMapping("/testTimeout")
    public String testTimeout() {
        String res = providerClient.testTimeout();
        return "consumer: " + res;
    }

    @GetMapping("/testException")
    public String testException() {
        String res = providerClient.testException();
        return "consumer: " + res;
    }

    @GetMapping("/testFallback")
    public String testFallback() {
        String res = providerClient.testFallback();
        return "consumer: " + res;
    }
}
